home *** CD-ROM | disk | FTP | other *** search
- program TestProg;
- { This program is a skeleton test application which demonstrates a modeless status
- dialog as defined in the Status unit. Choosing the single menu item causes a
- modeless status box to be displayed. For five seconds, the contents of the dialog
- are updated showing the amount of elapsed time. Clicking the cancel button or
- otherwise cancelling the box (typing escape or choosing close from the system menu)
- terminates the process before the five seconds have elapsed
-
- Contributed By: Adam Carney 71150,2436}
-
-
- {$R TEST.RES}
-
- uses WinTypes, WinProcs, OWindows, Strings, Status;
-
- const {$I CONST.PAS}
-
- type
- TTestApp = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PMainWindow = ^TMainWindow;
- TMainWindow = object(TWindow)
- constructor Init(AParent:PWindowsObject; ATitle:PChar);
- procedure CMLengthy(var Msg:TMessage);
- virtual cm_First + cm_Lengthy;
- end;
-
- procedure TTestApp.InitMainWindow;
- begin
- MainWindow := New(PMainWindow,Init(nil,'Test'));
- end;
-
- constructor TMainWindow.Init(AParent:PWindowsObject; ATitle:PChar);
- begin
- inherited Init(AParent,ATitle);
- Attr.Menu:=LoadMenu(HInstance,PChar(MainMenu));
- end;
-
- procedure DoSomethingLong(StatDlg:PStatusDlg);
- var
- StartCount, TicksElapsed:Longint;
- Tenths,Seconds:word;
- Temp:array[0..2]of char;
- Temp2:array[0..15]of char;
- begin
- StartCount:=GetTickCount;
- TicksElapsed:=0; Seconds:=1; Tenths:=1;
- while (TicksElapsed<5000) and StatDlg^.Continue do
- { Note: Elapsed time AND state of continue flag in the dialog govern while loop }
- begin
- if TicksElapsed div 1000 <> Seconds then
- begin
- Seconds:=TicksElapsed div 1000;
- Str(Seconds:2,Temp);
- StrCopy(Temp2,'Seconds: ');
- StrCat(Temp2,Temp);
- { Change the 2nd line in the dialog to reflect # of seconds elapsed }
- StatDlg^.Update(id_Stat2,@Temp2);
- end;
- if TicksElapsed div 100 <> Tenths then
- begin
- Tenths:=TicksElapsed div 100;
- Str(Tenths:2,Temp);
- StrCopy(Temp2,'Tenths: ');
- StrCat(Temp2,Temp);
- StatDlg^.Update(id_Stat3,@Temp2);
- { Change the 3rd line in the dialog to reflect # of tenths elapsed }
- end;
- TicksElapsed:=GetTickCount-StartCount;
- end;
- end;
-
- procedure TMainWindow.CMLengthy(var Msg:TMessage);
- var
- Dlg:PStatusDlg;
- i:word;
- begin
- { Create new TStatusDlg object }
- Dlg:=New(PStatusDlg,Init(@Self,'Lengthy','Counting...','Operation Cancelled'));
- { Create interface element and display the box on-screen }
- Application^.MakeWindow(Dlg);
- { Call a lenthy procedure; Pass it a pointer to the dialog }
- DoSomethingLong(Dlg);
- { Check state of continue flag and respond accordingly }
- if Dlg^.Continue then
- Dlg^.Complete('Done: 5 seconds have elapsed');
- { else
- the process was cancelled }
- end;
-
- var
- Test: TTestApp;
-
- begin
- Test.Init('Test');
- Test.Run;
- Test.Done;
- end.
-